<table width="100%"><tr><td width="20%">
<a href="../index.html">&lt; index</a><br />
<a href="index.html">&lt; 8. All purposes container</a><br />
</td><td width="60%">
<p align="center">
=====================================<br />
8.1 Creating a list<br />
=====================================<br />
</p></td><td width="20%">
<a href="list_array.html">&gt; 8.2 Basic array operations</a>
</td></tr></table>
<style type="text/css">
.code { color:#444444; background-color:#EEEEEE;}
pre { color:#444444; background-color:#EEEEEE;}
table.param td { border : 1px solid #000000; }
th { background-color: #44BBFF; color: #FFFFFF }
table.none td { border : 0 }
</style>
You can create an empty list with the default constructor. The C version returns a handler on the list.<br />
<p class="code"><pre>
C++ : template &lt;class T&gt; TCODList::TCODList()
C   : TCOD_list_t TCOD_list_new()
</pre></p>
<br />
Example :<br />
<p class="code"><pre>
C++ : TCODList&lt;int&gt; intList;
      TCODList&lt;float&gt; *floatList = new TCODList&lt;float&gt;();
C   : TCOD_list_t intList = TCOD_list_new();
      TCOD_list_t floatList = TCOD_list_new();
</pre></p><br />
You can also create a list by duplicating an existing list.<br />
<p class="code"><pre>
C++ : template &lt;class T&gt; TCODList::TCODList(const TCODList<T> &l)
C   : TCOD_list_t TCOD_list_duplicate(TCOD_list_t l)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>l</td><td>Existing list to duplicate.</td></tr>
</table>
<br />
Example :<br />
<p class="code"><pre>
C++ : TCODList&lt;int&gt; intList;
      intList.push(3);
      intList.push(5);
      TCODList&lt;int&gt; intList2(intList); // intList2 contains two elements : 3 and 5
C   : TCOD_list_t intList = TCOD_list_new();
      TCOD_list_push(intList,(const void *)3);
      TCOD_list_push(intList,(const void *)5);
      TCOD_list_t intList2 = TCOD_list_duplicate(intList); /* intList2 contains two elements : 3 and 5 */
</pre></p>
<br />
You can also create an empty list and pre-allocate memory for elements. Use this if you know the list size and want the memory to fit it perfectly.<br />
<p class="code"><pre>
C++ : template &lt;class T&gt; TCODList::TCODList(int nbElements)
C   : TCOD_list_t TCOD_list_allocate(int nbElements)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>nbElements</td><td>Allocate memory for nbElements.</td></tr>
</table>
<br />
Example :<br />
<p class="code"><pre>
C++ : TCODList&lt;int&gt; intList(5); // create an empty list, pre-allocate memory for 5 elements
C   : TCOD_list_t intList = TCOD_list_allocate(5);
</pre></p>



